package com.zx.controller.dj;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zx.model.dj.StockMaster;
import com.zx.service.dj.DataShowService;
import com.zx.service.user.UserService;
import com.zx.utils.web.Pagination;  
  
/**
 * 
 * @author zx
 *
 */
@Controller
@RequestMapping("dataShow")
public class DataShowController {
    
    @Resource  
    private UserService userService;
    
    @Autowired
    DataShowService dataShowService;
    
    @RequestMapping("toShopsSale")
    public String toShopsSale(Model model){
        return "dj/ShopsSale";
    }
    @RequestMapping("toRemind")
    public String toRemind(Model model){
        return "dj/Remind";
    }
    @RequestMapping("toStock")
    public String toStock(Model model){
        return "dj/Stock";
    }
    
    /**
     * 分仓库存
     * 
     * @param model
     * @return
     */
    @RequestMapping("selSaleRecords")
    public String selSaleRecords(Model mod, 
            @RequestParam(defaultValue="1", required=false)Integer pageIndex,
            @RequestParam(defaultValue="10", required=false)Integer pageSize, 
            @RequestParam(defaultValue="0", required=false)int orderType
            ,@RequestParam(defaultValue="", required=false)String sbrand
            ,@RequestParam(defaultValue="", required=false)String smodel
            ,@RequestParam(defaultValue="", required=false)String scolor
            ,@RequestParam(defaultValue="", required=false)String ssize
            ,@RequestParam(defaultValue="", required=false)String shopname
            ,@RequestParam(defaultValue="", required=false)String createTime
            ) {

        try {
            Integer total = dataShowService.selSaleRecordCount(sbrand,smodel,scolor,ssize,shopname,createTime);
            List<StockMaster> rst = dataShowService.selSaleRecordCondition(pageIndex, pageSize, orderType,sbrand,smodel,scolor,ssize,shopname,createTime);
            Pagination<StockMaster> pagination = new Pagination<>(pageIndex, pageSize, total);
            pagination.setData(rst);
            mod.addAttribute("pagination", pagination);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        mod.addAttribute("sbrand", sbrand);
        mod.addAttribute("smodel", smodel);
        mod.addAttribute("scolor", scolor);
        mod.addAttribute("ssize", ssize);
        mod.addAttribute("shopname", shopname);
        mod.addAttribute("createTime", createTime);
        
        return "dj/ShopsSale";
    }
}